package com.evil.kingdom.controller.person.king;

import com.evil.common.core.entity.R;
import com.evil.kingdom.pojo.entity.person.king.King;
import com.evil.kingdom.service.person.king.KingService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 君主
 *
 * @author liyang
 * @date 2024-05-22 17:11
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/king")
public class KingController {

    private final KingService kingService;

    /**
     * 新增君主
     *
     * @param king king
     * @return R
     */
    @PostMapping("/add")
    public R<King> add(@RequestBody @Validated King king) {
        return R.success(kingService.add(king));
    }

    /**
     * 更新君主
     *
     * @param king king
     * @return R
     */
    @PostMapping("/update")
    public R<King> update(@RequestBody @Validated King king) {
        return R.success(kingService.update(king));
    }

    /**
     * 查询君主
     *
     * @param name name
     * @return R
     */
    @RequestMapping("/find-by-name")
    public R<King> findByName(String name) {
        return R.success(kingService.findByName(name));
    }
}
